#include <iostream>
#include <deque>

#include "Image.H"
#include "Util.H"
#include "IO.H"
#include "rgm.h"

using namespace std;
using namespace pip;

int main(int argc, char *argv[])
{
  if (argc < 6) {//get input
	  error("", "Usage: grow_connect -i <input image> -seed <'x y [z]'> -connectivity <{4,6,8,18,26}> \n");
  }
  vector<string> args(argv, argv + argc);


  Image<float> in_float;
  Image<short> in_short;
  Image<unsigned char> in_char;
  Image<Color<unsigned char> > in_color;
  Image<unsigned char> out;

  string inputname;
  vector<int> seed;
  int n(0), object(0);
  unsigned char target = 1;

  getScalarArg(args, "-i", inputname); 
  getScalarArg(args, "-connectivity", n);
  getVectorArg(args, "-seed", seed);
  seed.resize(3);

  if (importFile(in_float, inputname))  //find image format
  {
      object = connect2(in_float , out, target, n, seed[0], seed[1], seed[2]);
  } else if (importFile(in_short, inputname)) 
  {
      object = connect2(in_short , out, target, n, seed[0], seed[1], seed[2]);
  } else if (importFile(in_char, inputname)) 
  {
	  object = connect2(in_char , out, target, n, seed[0], seed[1], seed[2]);
  } else if (importFile(in_color, inputname)) 
  {
	  object = connect2(in_color, out, target, n, seed[0], seed[1], seed[2]);
  } else 
  {   
	  cout << "The inputimage is not an Image of pixeltype: [unsigned char(also colored), short or float] !\n";
      //return 4;
  }
  
//print results
  cout << "Object from file "
	   << inputname 
	   << "with seed ("
	   << seed[0] << "," << seed[1] << "," << seed[2] << ") contains "
	   << object
	   << " voxels.\n \a";

  if (!exportFile(out, "output_connect.pip"))
	  cout << "unable to write output file onto disk...\n";

system("pause");

}
